import axios from 'axios'
import nprogress from 'nprogress'
import 'nprogress/nprogress.css'

const instance = axios.create({
  baseURL: 'https://lianghj.top:8888/api/private/v1/',
  timeout: 5000
})

// axios 请求拦截器
instance.interceptors.request.use(config => {
  config.headers.Authorization = window.sessionStorage.getItem('token')
  nprogress.start()
  return config
}, error => {
  return Promise.reject(error)
})

// axios 相应拦截器
instance.interceptors.response.use(response => {
  nprogress.done()
  return response
}, error => {
  return Promise.reject(error)
})

export default instance